package com.kylin.core.marketing.web.facade.impl;

import com.kylin.core.marketing.query.handler.MarketingTranslator;
import com.kylin.domain.marketing.command.QueryMarketingCampaignCommand;
import com.kylin.domain.marketing.provider.MarketingProvider;
import com.kylin.marketing.api.dto.req.QueryBoardMarketingReqDTO;
import com.kylin.marketing.api.dto.resp.MarketingBoardRespDTO;
import com.kylin.marketing.api.web.facade.MarketingPlatformFacade;
import com.kylin.shared.common.PageResults;
import com.kylin.shared.common.Pagination;
import com.kylin.shared.common.ResponseWrapper;
import com.kylin.shared.common.anno.ArgsValid;
import com.kylin.shared.enums.MarketingType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * 营销业务接口
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年12月19日 11:11
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "营销开放接口")
public class MarketingPlatformFacadeImpl implements MarketingPlatformFacade {

    private final MarketingProvider provider;
    private final MarketingTranslator translator;

    @ArgsValid
    @Override
    @ApiOperation(value = "获取营销商品列表", notes = "分页获取营销商品列表")
    public ResponseWrapper<Pagination<MarketingBoardRespDTO>> list(QueryBoardMarketingReqDTO queryMarketingReq) {
        PageResults campaigns = provider.findMarketingBoard(
                QueryMarketingCampaignCommand.builder()
                        .pageSize(queryMarketingReq.getLimit())
                        .pageIndex(queryMarketingReq.getIndex())
                        .type(MarketingType.GROUPON).build()
        );
        return new ResponseWrapper<>(new Pagination<>(
                campaigns.getIndex(),
                campaigns.getLimit(),
                campaigns.getTotal(),
                campaigns.castResults(MarketingBoardRespDTO.class)
        ));
    }

    @ArgsValid
    @Override
    @ApiOperation(value = "获取营销商品详情", notes = "根据方案Id获取营销商品详情")
    public ResponseWrapper<MarketingBoardRespDTO> find(String campaignId) {
//        provider
        return new ResponseWrapper<>();
    }
}
